using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PharmacyDomain;
using ShivamEMR.Model.DataInterfaces.CommonDataInterf;
using ShivamEMR.Model.DataInterfaces.PersonDataInterf;
using ShivamEMR.Model.DataInterfaces.PharmacyDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Pharmacy.Models;

namespace ShivamEMR.Web.Areas.Pharmacy.Controllers
{   
    public class DosageController : Controller
    {
		private readonly IUnitRepository unitRepository;
		private readonly IPersonStageRepository personstageRepository;
		private readonly IDosageRepository dosageRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DosageController()
        {
            unitRepository = Registry.RepositoryFactory.GetUnitRepository();
            personstageRepository = Registry.RepositoryFactory.GetPersonStageRepository();
            dosageRepository = Registry.RepositoryFactory.GetDosageRepository();
        }

        public DosageController(IUnitRepository unitRepository, IPersonStageRepository personstageRepository, IDosageRepository dosageRepository)
        {
			this.unitRepository = unitRepository;
			this.personstageRepository = personstageRepository;
			this.dosageRepository = dosageRepository;
        }

        //
        // GET: /Dosage/

        public ViewResult Index()
        {
          //  return View(dosageRepository.AllIncluding(dosage => dosage.Unit));
            return View(dosageRepository.All);
        }

        //
        // GET: /Dosage/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(dosageRepository.Find(id));
        }

        //
        // GET: /Dosage/Create

        public ActionResult Create()
        {
			ViewBag.PossibleUnits = unitRepository.All;
			ViewBag.PossiblePersonStages = personstageRepository.All;
            return View();
        } 

        //
        // POST: /Dosage/Create

        [HttpPost]
        public ActionResult Create(Dosage dosage)
        {
            if (ModelState.IsValid) {
                dosageRepository.InsertOrUpdate(dosage);
                dosageRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleUnits = unitRepository.All;
				ViewBag.PossiblePersonStages = personstageRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Dosage/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleUnits = unitRepository.All;
			ViewBag.PossiblePersonStages = personstageRepository.All;
             return View(dosageRepository.Find(id));
        }

        //
        // POST: /Dosage/Edit/5

        [HttpPost]
        public ActionResult Edit(Dosage dosage)
        {
            if (ModelState.IsValid) {
                dosageRepository.InsertOrUpdate(dosage);
                dosageRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleUnits = unitRepository.All;
				ViewBag.PossiblePersonStages = personstageRepository.All;
				return View();
			}
        }

        //
        // GET: /Dosage/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(dosageRepository.Find(id));
        }

        //
        // POST: /Dosage/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var dose = dosageRepository.Find(id);
            dosageRepository.Delete(dose);
            dosageRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

